<%@ page language="java"
    import="com.gorge4j.user.*,com.gorge4j.user.dto.*,com.gorge4j.user.vo.*,com.gorge4j.user.constant.*,java.util.*"
    contentType="text/html; charset=utf-8" pageEncoding="utf-8"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="viewVO" class="com.gorge4j.user.vo.ViewVO" scope="page" />
<jsp:useBean id="businessOperationBean" class="com.gorge4j.user.BusinessOperationBean" scope="page" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>查看用户</title>
</head>
<body>
    <%
        // 通过session来控制访问的权限，只有管理员用户才可以查看用户列表
        UserSessionDTO userSession = (UserSessionDTO) session.getAttribute("userSession");
        try {
            if (userSession == null || !("admin".equals(userSession.getName())
                    && UserTypeConstant.ADMIN.equals(userSession.getType())) || !userSession.getIsLogin()) {
                response.sendRedirect("login.jsp");
            }
        } catch (Exception e) {
            response.sendRedirect("login.jsp");
        }

        List<ViewVO> lstViewVOs = businessOperationBean.view();
        // 打印数据的表头
        out.println("<table border = \"1\" cellspacing = \"0\" >");
        out.println("<tr>");
        out.println("<td>ID</td>");
        out.println("<td>名字</td>");
        out.println("<td>用户类型</td>");
        out.println("<td>注册时间</td>");
        out.println("<td>操作类型</td>");
        out.println("</tr>");
        // 有记录时拼装数据
        if (!lstViewVOs.isEmpty()) {
            for (ViewVO viewVo : lstViewVOs) {
                out.println("<tr>");
                out.println("<td>" + viewVo.getId() + "</td>");
                out.println("<td>" + viewVo.getName() + "</td>");
                out.println("<td>" + viewVo.getType() + "</td>");
                out.println("<td>" + viewVo.getGmtCreate() + "</td>");
                out.println("<td><a href=\"del_user.jsp?id=" + viewVo.getId() + "\">删除</td>");
                out.println("</tr>");
            }
        }
        // 打印表格的结束标签
        out.println("</table>");
    %>
</body>
</html>